//
//  SettingViewController.swift
//  1604_LimitFree
//
//  Created by 千锋 on 16/9/29.
//  Copyright © 2016年 Mabin. All rights reserved.
//

import UIKit

class SettingViewController: LFNavViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.cyanColor()

         createBtns()
    }
    
    //导航
    override func createMyNav() {
        addBackButton()
        addnavTitle("设置")
    }
    
    //按钮
    func createBtns()
    {
        let imageArray = ["account_setting@2x","account_favorite@2x","account_user@2x","account_collect@2x","account_download@2x","account_comment@2x","account_help@2x","account_candou@2x"]
        let titleArray = ["我的设置","我的关注","我的账号","我的收藏","我的下载","我的评论","我的帮助","蚕豆应用"]
        
        
        //循环创建按钮
        let colNum = 3 //一共有几列
        let butW : CGFloat = 60 //按钮的宽度
        let butH : CGFloat = 60 //按钮的高度
        let titleH : CGFloat = 20 //文字高度
        let offsetX : CGFloat = 50 //第一个按钮左边的间距
        let offsetY : CGFloat = 160 //第一个按钮的Y值
        let spaceX : CGFloat = (kScreenWidtn - offsetX * 2 - butW * CGFloat(colNum)) / (CGFloat(colNum) - 1) //设置列间距
        let spaceY : CGFloat = 80 //按钮之间的行间距

        for i in 0..<imageArray.count
        {
            //计算行号和列号
            let row = i / colNum
            let col = i % colNum
            let btnX = offsetX + (butW + spaceX) * CGFloat(col)
            let btnY = offsetY + (butH + spaceY + titleH) * CGFloat(row)
            //创建按钮
            let button = UIButton.createBtn(CGRectMake(btnX,btnY,butW,butH), title: nil, bgImageName: imageArray[i], target: self, action: "buttonClick:")
            button.tag = 1000 + i
            self.view.addSubview(button)
            
            //创建文字
            let label = UILabel.createlabelFrame(CGRectMake(btnX,btnY+butH,butW,titleH), title: titleArray[i], textAlignment: .Center)
            label.font = UIFont.systemFontOfSize(13)
            self.view.addSubview(label)
        }
    }
    
    
    func buttonClick(button : UIButton)
    {
        let index = button.tag - 1000
        if index == 3
        {
            let CVC = CollectViewController()
            self.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(CVC, animated: true)
        }
        
    }
}
